regex


htaccess similar cases like Facebook or Twitter issue


I have this piece of line in my htaccess that causes errors. I couldn't find a similar answer to my inadequate wording.
I am attempting to get "username/followers, username/following, etc" and also "settings/account, settings/password, etc". I stopped using sub folders for non-scripts and images, so everything is on the same level.
Now I know they have similar casing, but I am curious how Facebook, Twitter, etc manage to do this.
Do they condense to one large page to make it work? I know they prevent people from using settings and other root level names from being used, and I haven't quite gotten to that point myself.
RewriteRule ^([^/]+)$ profile_home.php?userdomain=$1 [L]
RewriteRule ^([^/]+)/([^/]+)$ profile_home.php?userdomain=$1&selection=$2 [L]
RewriteRule ^settings/$ profile_settings.php [L]
RewriteRule ^settings/([^/]+)$ profile_settings.php?selection=$1 [L]
RewriteRule ^settings/([^/]+)/([^/]+)$ profile_settings.php?selection=$1&upload=$2 [L]
If I remove
RewriteRule ^([^/]+)/([^/]+)$ profile_home.php?userdomain=$1&selection=$2 [L]
Then everything works fine. How do I make this work with two pages?
I could do
RewriteRule ^settings/([^/]+)/$ profile_settings.php?selection=$1 [L]
But it doesn't look as nice. If not right place to ask, please let me know.
Your second rule matches both directory structures. You can use a negative lookahead so requests starting with the setting are not matched by that rule.
^(?!settings)([^/]+)/([^/]+)$
You can read more about lookaheads here:
http://www.rexegg.com/regex-lookarounds.html
http://www.regular-expressions.info/lookaround.html
Here is my solution
RewriteEngine On
# make sure to add your document root dir
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([\w-.]+)/?$ index.php?id=$1 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/htdocs/user/$2 -f
RewriteRule ^([\w-]+)/(.+)/?$ $2?id=$1&goto=$2 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/htdocs/user/$2/index.php -f
RewriteRule ^([\w-.]+)/([a-z0-9]+)/?$ $2/index.php?id=$1&goto=$2 [NC,L,QSA]
RewriteRule ^([\w-.]+)/([a-z0-9]+)/?$ index.php?id=$1&goto=$2 [NC,L,QSA]
so inside your server root dir htdocs/user/ you must have a folder like /user/ and a file index.php this htacess will replace the file site/user/index.php to site/user/username in the same user dir you need to have the following.php file so site/user/username/following.php in the same folder, I think you understand my answer.

Related Links

Regular expression validate CSV
can't extract a substring with regex
White list for Http verbs - Web.config Redirect rule
Optimizing a regex filled with '?'
How to extract all the content between two tags in XML with batch findstr? [duplicate]
Remove last character from the first word in a string
Finding Arbitrarily Long Word Patterns using Regular Expression in Python
Perl regex variable for replacement count
nginx pretty rewriting one parameter
Perl regex matching: keywords may or may not exist
How to match parenthesis in StanfordNLP regexNER?
Extracting Blocks of Information from txt file and create a Pandas dataframe and store
RegExp for Indian Bank Account Number
Logstash stops compiling when given custom pattern inside a filter
Extract MAC address and UUID from string
XSD identifier pattern

Categories

HOME
ssis
odoo-10
f#
watson
swashbuckle
streaming
stripe-payments
oracle-adf
py.test
drag
wav
gcov
xorg
session-cookies
jquery-jtable
reload
scale
python-2.5
partitioning
accumulo
orientdb-2.1
swig
jscodeshift
pydev
revitpythonshell
similarity
digital-logic
italic
android-security
parallax.js
true-type-fonts
popupwindow
akka-http
cloudinary
ollydbg
webcenter
google-domain-api
outlook-vba
mask
confirm
zipline
msal
apartment-gem
dsx
amazon-vpc
btle
ulimit
syncfusion
zfs
formstack
stroke
dump
soql
node.js-tape
ammonite
biological-neural-network
manual
itertools
omniauth
findall
wxhaskell
informatica-cloud
perspective
sound-synthesis
xceed
ellipsis
dms
target-platform
ota
flotr2
schematiq
vimeo-ios
pakyow
occam-pi
xelement
post-processor
push-api
xsb
telescope
abort
misra
culture
ratingbar
sendto
dojo.gridx
email-spam
inputview
simpleaudioengine
deap
floating-point-conversion
polarssl
geometry-surface
timespan
guvnor
freeglut
j#
custom-tag
cracker

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App