I'm trying to rewrite my url, but I'm getting an error "500 Internal Server Error"
I've never done this before, and I've read some tutorials but I can't say I got any smarter from it.
The .htaccess file is in the root directory (/var/www)
Options +FollowSymLinks
RewriteEngine On
RewriteBase /sub_domain/directory_to_my_files/
RewriteRule ^([0-9.]+)-([0-9.]+)/(.*)/$ /index.php?pos=$1:$2&text=$3
The current link goes like this:
http://sub_domain.my_domain.com/directory_to_my_files/index.php?pos=(float|integer-only):(float|integer-only)&text=(any-text)
But I'm trying to do this:
http://sub_domain.my_domain.com/directory_to_my_files/(float|integer-only):(float|integer-only)/(any-text)/
Sorry if the links is a bit hard to read.
This should be placed in /directory_to_my_files/.htaccess
RewriteEngine On
RewriteBase /directory_to_my_files/
RewriteRule ^(-?[0-9.]+)[:-]([0-9.]+)/([^/]+)/?$ index.php?pos=$1:$2&text=$3 [L,QSA,NE]
I've tested this locally:
( I did not need the rewrite base )
RewriteEngine on
RewriteRule ^([0-9.]+)-([0-9.]+)/(.*) /index.php?pos=$1:$2&text=$3 [R,L]
And it has redirected me
from
http://loc.domain/555-666/misc-text
to
http://loc.domain/index.php?pos=555:666&text=misc-text
I reckon this was what you wanted?
About the [R,L] at the end:
the R is telling apache to actually redirect, not just rewrite the url - this helps with testing.
the L is saying this is the last rule
Edit: could it be that the rewriteBase is causing you problems? Try it without and see if it works - at least you can nail where the problem is, then.
Related
I'm working on a subdirectory, and want to rewrite ugly file-urls into prettier URLs.
Like:
domain.com/myfolder/myreport.php --> domain.com/myfolder/MyReport/
Here's what I have:
RewriteEngine On
RewriteRule ^test/?$ index.php [NC,L]
Taken from here
However, it's not working. I've tested every combination of regex I could imagine, nothing worked.
Are there any other potential problems? Is it possible that all rules are ignored/overwritten by a rule in the root directory or something?
The .htaccess IS being used, if I add "test", I get a 500 Error.
Can you just try the following,
RewriteEngine on
RewriteBase /myfolder/
RewriteRule ^(.*)$ /myfolder/index.php?/$1 [L]
i am using godaddy hosting and addon domain. i want to make my long url to short url.
for example my url is follwing:
www.example.com/events/landing_event.php?url=text-first
and i want following url:
www.example.com/events/text-first
for this i am using following rewrite url in .htaccess file
RewriteRule ^([a-zA-Z0-9-/]+)$ events/landing_event.php?url=$1 [L]
RewriteRule ^([a-zA-Z0-9-/]+)/$ events/landing_event.php?url=$1 [L]
but this rewrite rule is not working.
so please help how can i make short url.
Use this source after you make sure RewriteEngine Enabled and On
RewriteEngine On
RewriteRule ^events/([^/]*)$ /events/landing_event.php?url=$1 [L]
The original URL:
http://www.example.com/events/landing_event.php?url=text-first
The rewritten URL:
http://www.example.com/events/text-first
Updated with 500 Internal Server Error
Your code is guaranteed to generate 500 internal server error because it is causing infinite looping. Reason is that your matching URI pattern is: ^events/([^/]*)$
Which matches your URLs before and after rewrites. And once it reaches max allowed internal rewrite limit Apache throws 500 internal server error and bails out.
Change your code to this
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^events/([^/]*)$ /events/landing_event.php?url=$1 [L,QSA,NC]
Try this code :
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /events/landing_event.php?url=$1 [L]
Add this in your .htaccess file
You can see there are many ways to achieve that goal.
Also
RewriteEngine On
RewriteRule ^events/([^/]*)\.html$ /events/landing_event.php?url=$1 [L]
would do the job. So basicly, how does the full scope of your project urls look like?
Like do you always want to print the parameters? If yes, also the name sometimes or also the value?
The newer versions of apache requires you to change AllowOverride on /etc/apache2/apache2.conf
from
AllowOverride None
to
AllowOverride All
Here is my .htaccess:
RewriteEngine on
RewriteRule !\.(js|ico|gif|ini|jpg|png|css|html|swf|flv|xml)$ index.php
I've been using this file for about a year now and frankly, if you ask me I'd say it means: If you're trying to access something NOT ended with js, ico, gif... flv, xml THEN redirect to index.php
Now I'm trying to deploy an application at a new server (centOS WITH mod_rewrite enabled) and I get the Error 404 when trying to access stuffs that usually works (at a different web server, for instance).
Since I know too little about it, I'd like some input on what should I be looking for to find the problem. Thanks in advance.
You should perform that kind of match in RewriteCond
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !\.(js|ico|gif|ini|jpg|png|css|html|swf|flv|xml)$
RewriteRule .* index.php
Note: the first rule is needed so that the rules won't loop (exclude index.php itself from rewriting).
Ok, I'm starting to think that the problem is me but... ¿What's wrong here?
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule testpage\.html http://www.google.com [R] #It works
RewriteRule ^mineral/([0-9]+)/?$ ver.php?id=$1 [NC,L] #It doesn't
I have a folder called "WebX" and this .htaccess inside it along with other files from the web.
mod_rewrite is working ok according to phpinfo and everything is running on localhost.
The most courious thing is that if I type localhost/WebX/testpage.html it redirects to Google
but unfortunately for me if I type localhost/WebX/mineral/1 it gives me 404. ¿What happens?
The problem you are having is caused by RewriteBase /. Your .htaccess is in a subdirectory /WebX/, but you are telling mod_rewrite to rewrite rules as if the current directory was /. It tries to load a file ver.php in your www-root, which doesn't exist. If you have verbose error messages with what file it tried to load, you'll notice it says that it tried to load /ver.php and not /WebX/ver.php as you might expect.
The rest you are doing, most notably using a relative url instead of a / prefixed absolute url, seems correct. The correct .htaccess to use would be:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /WebX/
RewriteRule testpage\.html http://www.google.com [R] #It works
RewriteRule ^mineral/([0-9]+)/?$ ver.php?id=$1 [NC,L] #It now should work
I would like to write a rule where the members/show/ string will be hidden in the URL.
The original URL: localhost:8080/sandbox/member/show/helloworld, where helloworld is the name of the account. I'd like it to be localhost:8080/sandbox/m/helloworld. Basically, the content delivered will be from the full url, but I'd like it to be hidden for any user.
RewriteRule ^.*$ member/show/$0 [L,QSA] doesn't seem to work, it throws a 500 Internal Server Error. I work with the CodeIgniter Framework, and the following rewrite rule is already present: RewriteRule .* index.php/$0 [PT,L].
I tried several RewriteRule options but without success. I'd be very glad if anyone could shed some light related to my question.
Best regards.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(sandbox)/m/([^/]+)/?$ /$1/member/show/$2 [L,NC]