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 do I create a regex in Emacs to capture text between double square brackets?
How to set a RegExp to have a real matching judgement?
Editing a line of a configuration file from shell
Perl replace the top-level numbers only from a tree
Regular Expressions match exactly 7 or 9 digits
How to accept numbers and specific words?
Javacc regular expression that matches all string except certain ones
perl regex - extract words between 2 separators
Regex number extraction
How to delete slash from the str?
how to use regex to strip the preprocessor directive
Find a string in multiple files using grep
Regex find and replace over multi lines in Shell
Grepping a 20g file in bash
What Perl matching regexp nuances can cause headaches?
What is the invalid URI error from SpamAssassin actually matching?

Categories

HOME
openshift-origin
apache-pig
apacheds
path
passwords
calayer
openmodelica
cloudrail
spring-boot-admin
slowcheetah
formio
textmatebundles
nintex-workflow
opencms
mouseevent
polynomials
background-subtraction
physics
toolbar
f2py
ocean
concurrenthashmap
apache-commons-httpclient
localdb
pyparsing
haxm
rhel7
deep-copy
azure-app-service-envrmnt
spring-data-cassandra
jackrabbit
mask
powerbuilder-conversion
kmdf
ipod-touch
ibm-wcm
rft
procobol
qmake
backwards-compatibility
nscalendar
program-slicing
kendo-chart
autofocus
uifont
spring-form
vega-lite
android-gps
html-lists
biological-neural-network
tastypie
geneticsharp
turbo-c
sizing
agile-processes
tachyon
surroundscm
jasny-bootstrap
ellipsis
singly-linked-list
pager
selenium2library
mutation
schematiq
aplpy
asp.net-webpages
docklight
radix-sort
linq2db
android-listfragment
cbc-mode
vbo
spatial-index
abort
fastparse
mkpolyline
iife
jasmin
boxapiv2
razor-2
epoll
httpservice
jquery-backstretch
grunt-contrib-copy
inputview
re2c
libnids
rcu
globbing
dynamic-usercontrols
wpf-4.0
working-directory
zmodem
rgba
ed
semantic-zoom
bapi
ondraw
ramaze
closest
blackberry-os-v5
jtemplates
nsindexset
regexbuddy
drwatson
code-statistics
plumtree

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