I have the following code on my .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^cp/artes-escenicas/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^cp/ciencia-y-tecnologia/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^cp/arte-y-diseno/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^cp/deportes/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^cp/idiomas/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^cp/academico/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^cp/rutas/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^cp/voluntariado/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
this allow me to have the following URL's:
http://pepperscope.com/cp/index.php
http://pepperscope.com/cp/artes-escenicas
http://pepperscope.com/cp/ciencia-y-tecnologia
http://pepperscope.com/cp/arte-y-diseno
http://pepperscope.com/cp/arte-y-diseno
http://pepperscope.com/cp/deportes
http://pepperscope.com/cp/campamentos
http://pepperscope.com/cp/idiomas
http://pepperscope.com/cp/academico
http://pepperscope.com/cp/rutas
http://pepperscope.com/cp/voluntariado
http://pepperscope.com/cp/lifestyle
But I need two things:
1) have the root on pepperscope.com instead of pepperscope.com/cp/index.php
2) remove the cp folder from all my links, like that:
http://pepperscope.com/artes-escenicas
http://pepperscope.com/ciencia-y-tecnologia
http://pepperscope.com/arte-y-diseno
http://pepperscope.com/arte-y-diseno
http://pepperscope.com/deportes
http://pepperscope.com/campamentos
http://pepperscope.com/idiomas
http://pepperscope.com/academico
http://pepperscope.com/rutas
http://pepperscope.com/voluntariado
http://pepperscope.com/lifestyle
Thanks in advance for your help.
You just need to remove the cp after ^, so something like this.
Remove all cp folders from all links
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^artes-escenicas/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^ciencia-y-tecnologia/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^arte-y-diseno/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^deportes/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^idiomas/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^academico/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^rutas/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^voluntariado/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
To fix the problem with the root, best thing I can come up with is this
RewriteRule ^([/]?)$ cp/index.php
Related
I am trying to rewrite my page like abc.com/profile.php?id=abc to abc.com/abc
Can you guide me?
When I try to add the following line, i getting 500 page error
RewriteRule ^([^/]*)$ /profile.php?id=$1 [L]
my htaccess
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /detail.php?type=$1&title=$2&id=$3 [L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?pn=$1&type=$2 [L]
RewriteRule ^contact-us.html$ contact-us.php [NC,L]
RewriteRule ^about-us.html$ /about-us.php [NC,L]
RewriteRule ^privacy-policy.html$ /privacy-policy.php [NC,L]
RewriteRule ^legal.html$ /legal.php [NC,L]
RewriteRule ^search$ /search.php [NC,L]
RewriteRule ^disclaimer.html$ /disclaimer.php [NC,L]
RewriteRule ^submit-job$ /submit-job.php [NC,L]
I'm trying to make a .htaccess redirect to some webpages as usual.
Here's how I got it working:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^Profile/(.+)/?$ index.php?page=profile&username=$1 [NC,L]
RewriteRule ^profile/(.+)/?$ index.php?page=profile&username=$1 [NC,L]
RewriteRule ^Profile/Me index.php?page=profile [NC,L]
RewriteRule ^Profile/me index.php?page=profile [NC,L]
RewriteRule ^profile/Me index.php?page=profile [NC,L]
RewriteRule ^profile/me index.php?page=profile [NC,L]
RewriteRule ^Personagem/(.+)/?$ index.php?page=personagem&personagem=$1 [NC,L]
RewriteRule ^personagem/(.+)/?$ index.php?page=personagem&personagem=$1 [NC,L]
And here is what I need: When I'm on "Personagem" page, I can access all "Albums", on the following URL:
/Personagem/--name of character--/Album
Being, --name of character--, the parameter of /Personagem. Is it possible?
You can use:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profile/(.+)/?$ index.php?page=profile&username=$1 [NC,L]
RewriteRule ^profile/me index.php?page=profile [NC,L]
RewriteRule ^personagem/([^/]+)/?$ index.php?page=personagem&personagem=$1 [NC,L]
RewriteRule ^personagem/([^/]+)/([^/]+)/?$ index.php?page=personagem&personagem=$1&album=$2 [NC,L]
You can add other with:
RewriteRule ^personagem/([^/]+)/([^/]+)/([^/]+)/?$ index.php?page=personagem&personagem=$1&album=$2&other=$3 [NC,L]
No need to add PrOfILE or PROfILe... with NC (no case)
I am not facing another problem with my mod_rewrite, first, time is my .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^news/([0-9]+)/?$ /news?id=$1 [L,QSA]
RewriteRule ^contact/([0-9]+)/?$ /contact?do=$1 [L,QSA]
RewriteRule ^account/([a-zA-Z]+)/?$ /account?action=$1 [L,QSA]
RewriteRule ^admin/([a-zA-Z]+)/?$ /admin?action=$1 [L,QSA]
RewriteRule ^login/([a-zA-Z]+)/?$ /login?action=$1 [L,QSA]
RewriteRule ^register/([a-zA-Z]+)/?$ /register?action=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L] <- This line doesn't work
RewriteRule ^([\w\d~%.:_\-]+)$ index.php?page=$1 [L,QSA]
All lines are working, beside the RewriteRule ^([^.]+)$ $1.php [NC,L]
and when I use this line, all other rules gets interrupted.
What am I doing wrong?
You need to use L flag in your problematic rule.
For removing the .php extension this is better rule:
Options +FollowSymlinks -MultiViews
RewriteEngine on
## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]
RewriteRule ^news/([0-9]+)/?$ /news?id=$1 [L,QSA]
RewriteRule ^contact/([0-9]+)/?$ /contact?do=$1 [L,QSA]
RewriteRule ^account/([a-zA-Z]+)/?$ /account?action=$1 [L,QSA]
RewriteRule ^admin/([a-zA-Z]+)/?$ /admin?action=$1 [L,QSA]
RewriteRule ^login/([a-zA-Z]+)/?$ /login?action=$1 [L,QSA]
RewriteRule ^register/([a-zA-Z]+)/?$ /register?action=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^(.+?)/?$ index.php?page=$1 [L,QSA]
Try something like
#Preventing loop
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
RewriteCond %{REQUEST_URI} !^.+\.php.*$
RewriteRule .* - [L]
Put this after RewriteRule ^register/([a-zA-Z]+)/?$ /register?action=$1 [L,QSA]
i have a rewrite rule.
RewriteRule ^pages/(.+)$ info_pages.php?page_url=$1 [L]
this was working well Before.
my url like this but at localhost
http://dressgirls.com/demo2/pages/contact-us.html
this pointing to
http://dressgirls.com/demo2/info_pages.php
when i use this
echo $_GET['page_url'];
it gives me. contact-us.html/contact-us.html/contact-us.html
it should give contact-us.html one time only.
do you have idea what is wrong here.?
This is full code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^pages/(.+)$ info_pages.php?page_url=$1 [L]
RewriteRule ^reviews/(.+)$ edit_review.php?review_id=$1 [L]
RewriteRule ^deals/(.+)$ category.php [L]
RewriteRule ^city/(.+)$ location_deals.php [L]
#RewriteCond %{REQUEST_FILENAME} =-f
#RewriteRule ^(.*)\.php$ $1.html [NC,L]
#RewriteRule ^(.*)\.html$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} ^(.*)\.html$
RewriteCond %1.php -f
RewriteRule ^(.*)\.html$ $1.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ deal-detail-page.php [QSA,L]
</IfModule>
Thanks.
Change code to:
RewriteBase http://dressgirls.com/
RewriteRule ^pages/(.+)$ info_pages.php?page_url=$1 [L]
and try.
I have this in my .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^users/([^/]+)/?$ users.php?user=$1 [NC,L]
in my php I have
header("Location: /users/" . $_SESSION['user']);
it loads this into the browser
foo.bar/users/s2xi
which gives me a 404 Not Found error, I can understand up to the part where the directory users doesn't exist, but isn't my RewriteRule supposed to take care of that?
Edit: My complete .htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^foo\.bar$
RewriteRule (.*) http://www.foo.bar/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([a-zA-Z0-9_\s-]+)/([a-zA-Z0-9_\s-]+)(/)?$ users.php?type=$1&user=$2 [NC,R]
#RewriteRule ^users/?$ users.php [L]
RewriteRule ^([^/]+)/?$ profile.php?user=$1 [NC,L]
#RewriteRule ^users/([^/]+)/?$ users.php?user=$1 [NC,L]
#RewriteRule ^(admin)/(.+)/?$ users.php?user=$1 [NC,L]
RewriteRule ^admin/([^/]+)$ users.php?user=$1 [NC,L]
#error codes
RewriteRule ^/error/([^/]+)/ error.php?code=$1 [NC]
Change your .htaccess to the following:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^users/([^/]+)$ users.php?user=$1 [NC,L]
Also make sure users.php is in a right directory. If it's in root directory, you can use:
RewriteRule ^users/([^/]+)$ /users.php?user=$1 [NC,L]