I want to convert my link like this:
from http://example.com/pictures.php?title=new
to
http://example.com/new.
Here is my .htaccess; it's giving me a 500 internal server error.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteEngine On
RewriteRule ^([^/]*)$ /pictures.php?title=$1 [L]
</IfModule>
<IfModule mod_security.c>
# Turn off mod_security filtering.
SecFilterEngine Off
# The below probably isn't needed,
# but better safe than sorry.
SecFilterScanPOST Off
</IfModule>
What's wrong in it?
I suspect your rewrite may be causing a loop. A RewriteCond to avoid a loop is usually a good idea;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !=/pictures.php
RewriteRule ^([^/]*)$ /pictures.php?title=$1 [L]
You should avoid rewrtiing actual files like .js, .css and images to pictures.php. Try this rule:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /pictures.php?title=$1 [L,QSA]
you can try like this simply
RewriteEngine On
RewriteRule ^([^/]*)$ /pictures.php?title=$1 [L]
Related
I have a page in the following location: /property/happy_property_urls.php
My goal is to make the happy looking url's look like this: /en/london/apartment/for-rent/ww123/
I have tried various methods but none of them seem to stick and I only get 404 errors.
EXAMPLE NOT WORKING
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /property/
RewriteRule ^(.*?)$ happy_property_urls.php?lang=$1&city=$2&type=$3&status=$4&ref=$5 [NC,L,QSA]
</IfModule>
I am sadly failing badly.
Can someone give me some pointers please?
You can use this rule in the .htaccess in the root.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ property/happy_property_urls.php?lang=$1&city=$2&type=$3&status=$4&ref=$5 [NC,L,QSA]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^read(.+)?$ /read.php?id=$1 [QSA,L]
RewriteRule ^chapter(.+)?$ /readchapter.php?id=$1 [QSA,L]
RewriteRule ^list(.+)?$ /list.php?id=$1 [QSA,L]
</IfModule>
Above is my htaccess file, I trying create a story reading website.
I trying to shorten example link of
http://read.mydomain.com/chapter/three_little_fox/
So when it query
/chapter/three_little_fox
It will actually load readchapter.php?id=three_little_fox
But when I try load the page
http://read.mydomain.com/chapter/three_little_fox/
It throws a Internal 500 error.
Thanks for helping
The current .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^chapter/([^/]*)$ readchapter.php?id=$1 [L]
</IfModule>
But the 404 error exist, my folder is this way
.htaccess
readchapter.php
index.php
Try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^chapter/(.*)/?$ /readchapter.php?id=$1 [QSA,NC,L]
</IfModule>
RewriteCond (Rewrite Conditions) ensures that if the request is already for a file or directory, RewriteRule will be skipped.
This will work for you:
RewriteEngine On
RewriteRule ^chapter/([^/]*)$ /readchapter.php?id=$1 [L]
I'm trying to rewrite a URL using the following rule:
RewriteRule ^([^/]*)$ /curation.php?id=$1 [L]
and this is an .htaccess file I created:
RewriteEngine On
RewriteRule ^([^/]*)$ /curation.php?id=$1 [L]
but when I push it to my Heroku server, I get a 500 Internal Server Error on all pages. What am I doing wrong?
Thanks
I think the main problem is you rewrite rule
try something like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([^/]+) index.php?id=$1 [L]
</IfModule>
If you have mod_rewrite loaded, and your rules are in an htaccess file in your document root. The rules that you have are causing an infinite loop. You need to add a condition or two to prevent that:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/curation\.php
RewriteRule ^([^/]*)$ /curation.php?id=$1 [L]
Or
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /curation.php?id=$1 [L]
I'm using the Silex "micro-framework" for routing purposes of my application.
I'm currently stuck on how to rewrite the url with .htaccess.
Standard Silex url: localhost/myapp/web/index.php/hello/name
I want it to look like: localhost/myapp/hello/name
With the following .htaccess code, I'm able to omit the /index.php/ part. But I still have to use the /web/ part.
RewriteEngine On
RewriteCond %{THE_REQUEST} /myapp/web/index.php/
RewriteRule ^/myapp/web/index.php/(.*) /myapp/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !/myapp/web/index.php/
RewriteRule ^(.*)$ /myapp/web/index.php/$1 [L]
Any suggestions?
Thanks!
I've faced the same problem right now and the solution was to change .htaccess content to:
FallbackResource /index.php
So in your case it would be
FallbackResource /web/index.php
This worked for me and I hope someone will find it useful.
From: http://silex.sensiolabs.org/doc/web_servers.html
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
The right would be to set up your DocumentRoot to /path/to/your/app/web.
Something like this should do the trick:
RewriteEngine On
RewriteBase /
RewriteRule ^myapp/web/index.php/ /myapp/ [R=301,L]
RewriteRule ^myapp/ /myapp/web/index.php/ [L]
I had a similar problem, solved with the following
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)? index.php/$1 [QSA,L]
RewriteRule ^/?$ /web/ [R=301]
</IfModule>
Really simple request. I want my url to look like:
http://localhost/movie/72105
instead of this
http://localhost/movie?id=72105
I currently have this setup going on in my .htaccess file, but it does not seem to be working:
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-z\-]+)$ index.php?id=$1 [L]
</IfModule>
Just to clarify aswell, when the mod_rewrite is working successfully, I can still use to retrieve the ID?:
$_GET['id']
Much appreciated for any help.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^lab/movie/(\d+)$ index.php?id=$1 [L]
</IfModule>
Now, you can browse http://domain.com/movie/12 and $_GET['id'] will be 12.
I am using this one
Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
RewriteBase /
# Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
you can retrive the id and other parameters (mobvie) by parsing
$_SERVER['REQUEST_URI']
in your index.php than.
also see: http://httpd.apache.org/docs/current/mod/mod_rewrite.html