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

How to use sed to identify a string in brackets?
Regex getting url string
double task if pattern matches in Perl
how to remember regular expression quantifications?
Search if a string matches with any regex of an array in Perl
How to solve Nested quantifiers in regex?
Regex empty string or two-five commas
Regex.Replace unable to make it work
Regex conversion on bbcode
RegEX request with chinese characters
Pattern matching language knowledge, pattern matching approach
Printing the output to a file in perl
shell grep, regex to find a specific occurence
How can I delete all files that match a list of patterns with Perl?
why :%s/^$//g is not equal to :g/^$/d in vim?
Find and Replace using RegEx in SublimeText but just add formating

Categories

HOME
regex
apache-spark
odoo-10
ffmpeg
dom
music
identityserver4
codenameone
serial-port
blogs
apacheds
azure-web-sites
bolt-cms
design
bootstrap-selectpicker
xquery
webdriver-io
netbeans-8
microsoft-dynamics
py.test
wso2ei
cobol
marketplace
rgb
spring-boot-admin
pywin32
media-source
spring-restdocs
italic
coqide
concurrenthashmap
breakpoint-sass
localdb
stomp
server-sent-events
advanced-installer
phing
mask
macvim
confirm
packaging
json-rpc
internet-explorer-10
worldpay
pac
rtems
sql-insert
android-gps
orchestrate
ios-app-group
sshd
jawr
itertools
jcuda
omniauth
findall
turbo-c
mailcore2
hapi.js
business-logic
groupbox
flotr2
xlform
strace
flexigrid
java-gstreamer
clientid
linqtocsv
greenfoot
xirr
monkeyrunner
crosswalk
spinach
equinox
structured-programming
size-t
textmatching
mks
reactive-cocoa-3
excel-charts
bit.ly
office-2010
symfony-2.5
concurrentdictionary
private-methods
ash
ituneslibrary
showcaseview
siblings
memoization
progressdialog
virtual-earth
tempo
sender
domain-mapping
browserid
android-actionmode
ria
undeclared-identifier
time-limiting
livevalidation
plinqo
custom-protocol
wmd
run-length-encoding

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