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

search for specific characters within column and then create different columns from it
.htaccess URL rewriting adivce - remove text from url [closed]
Regex look for all quotes not preceded by a comma
Trying to get not greedy regex in omake
Sublime Text : Key Binding Regex for a New Line?
Regex: match X pattern but not Y [closed]
How to replace word in notepad++ that begins with certain word plus number of bytes
How to read numbers from extracted lines (deleting repeated numbers)
Regexp: match and exclude
Find multiple matches of this and that nucleotide sequence
In shell, how to judge a string start with a path name? [closed]
Regex for Special Characters in XQuery
add a tracking code to the first instance of a link in each line of a CSV file
Using sed to replace only inside a regexp substring
divide the string with RegExp in Groovy
Regexp to test capital letters in Unicode

Categories

HOME
ios
ssis
sharepoint-2013
module
youtube
spring-roo
outlook
image-segmentation
wxpython
fpdf
antlr
android-sms
antlr4
mvvm-light
android-dialer
asp.net-mvc-3
google-maps-sdk-ios
light-inject
jquery-jtable
scale
pyfftw
lag
accumulo
ssrs-2008
jruby
advantage-database-server
software-distribution
atg
py4j
jqplot
bitcode
background-subtraction
pvs-studio
jtable
asana-api
google-shared-contacts
lifecycle
gradient-descent
double-click-advertising
partition
linechart
pac
jpype
nexus-5
php-5.5
permgen
monogame
hostname
win2d
freecodecamp
sql-insert
http-status-code-500
formstack
jcuda
bosh-deployer
omniauth
ifc
sscanf
webtrends
finalcut
android-number-picker
python-3.1
okuma
highslide
linqtocsv
dnx
text-alignment
symbian
chunk-templates
node-orm2
bonfire
centering
mysql5
tab-delimited
jasmin
gnat
boxapiv2
imaging
datacontractserializer
spread-toolkit
modalpopupextender
xml.modify
cfile
sshj
floating-point-conversion
polarssl
programmers-notepad
zephir
xhtml-transitional
nsmanagedobjectmodel
squirrelmail
qbwc
rpn
arden-syntax
jetspeed2
postgresql-8.1
duplicate-data
sharepoint-timer-job
apache-config
queryanalyzer

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