I am trying to change the url of my webpage at localhost but i am unable to figure it out. I am using windows 7(64 bits).
I already uncomment the "LoadModule rewrite_module modules/mod_rewrite.so" and AllowOverride None to AllowOverride All.
I want to change my url "http://localhost/mywebsite/product_name.php?name=alfa" to something like that "http://localhost/product_name/alfa"
My .htaccess file code is below:
RewriteEngine on
RewriteBase /
RewriteRule ^([^/\.]+)/?$ product_name.php?name=$1 [L]"
my php file code is:
.....
Please help me I tried many changes in my htaccess file but could not find a solution
Change your php code to:
.....
Or add this rule:
RewriteCond %{THE_REQUEST} \ /+product_name\.php\?name=([^&\ ]+)
RewriteRule ^ /%1? [L,R]
Related
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
I am using WAMP and my url is localhost/hotel/hotels.php?id=21
Using rewrite rule as follow,
Options +FollowSymLinks
RewriteEngine on
RewriteRule hotels/id/(.*)/ hotels.php?id=$1
RewriteRule hotels/id/(.*) hotels.php?id=$1
But nothing happens..
My mod_rewrite is on and also changes done in httpd.conf file.
Please give me a suggestion to handle the issue?
You must use flags for your RewriteRule. You can change it as follow
RewriteEngine on
RewriteRule ^hotels/id/([\d]+)/?$ hotels.php?id=$1 [NC,L]
You can call your pages from
localhost/hotel/hotels/id/12
If your .htaccess file is located in localhost/hotel .
I need your help! (sorry for my bad english)
I try to do url rewriting in my localhost on Ubuntu13.10/Apache2.4.6 ...
I searched a lot of time on internet and problem is always here..
this is my .htaccess (I begin in url rewriting so I don't know if it's ok) :
RewriteEngine On
AllowFromAll All
RewriteRule home/ index.php?uc=home
and when I go to 127.0.0.1/mywebsite/home/ I have a 404 error.
My .htaccess is in : mywebsite/.htaccess
I activated url rewrite with "sudo a2enmod rewrite" and restarted apache.
I have no error in apache logs
I read solution who said I have to change AllowOverride to On in /etc/apache2/sites-available/default but I dont have /etc/apache2/sites-available/default file
I am lost...
Please, I don't know what to do...
After many tests : I think I have a problem of AllowOverride
You either need to specify the RewriteBase
RewriteBase /mywebsite/
RewriteRule home index.php?uc=home [L]
or add it to your rule
RewriteRule /mywebsite/home index.php?uc=home [L]
I think this is more like this :
RewriteRule is relative to the RewriteBase, so if your .htacess is in /mywebsite/ folder :
RewriteBase /
RewriteRule /home index.php?uc=home [L]
this way it should work, let me know ;)
So... If this is not working, let's start by the beginning.
Find httpd.conf
LoadModule rewrite_module libexec/mod_rewrite.so and AddModule mod_rewrite.c should be in there, and without comment mark (#)
In your .htaccess, there is :
# The server must follow symbolic links (this can help in some apache versions)
Options +FollowSymlinks
# RewriteEngine activation
RewriteEngine on
# RewriteRule
RewriteRule ^home$ index.php?uc=home [L]
This configuration works on my apache 2.2.22.
The truth is that
/index.php?uc=home [L]
points on http://127.0.0.1/index.php
instead of http://127.0.0.1/mywebsite/index.php
because of the DocumentRoot property. On a real domain, or /w a virtualhost pointing on /mywebsite/, /index.php?uc=home [L] should work.
Keep in mind that RewriteRule is relative to the DocumentRoot and RewriteBase can't resolves this problem.
I have a site that I would like to use Apache's RewriteRule to rewrite URLs.
I want:
http://baileyseymour.com/index.php?p=home
to rewrite to
http://baileyseymour.com/p/home
I have AMPPS installed on my Mac and I added the following lines to httpd.conf and they work successfully:
RewriteEngine On
RewriteRule ^/p/(.*) /index.php?p=$1 [PT]
I'm trying to do the same but on my server.
And I have added the same apache code to /public_html/.htaccess but I get the error message below:
Not Found
The requested URL /p/home was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
The exact same code works on my localhost server. Why not on my website?
Can you check your remote server apache supports "AllowOverride All" ?
also try this way maybe it will help.
RewriteEngine On
RewriteRule ^p/(.*) /index.php?p=$1 [PT]
but you may have to modify $_GET['p'] properly. which will be sent only "home" part.
You need to remove the leading slash from the rewrite rule's pattern. URI's have their leading slash removed when the rewrite engine applies rules in an htaccess file.
RewriteEngine On
RewriteRule ^p/(.*) /index.php?p=$1 [PT]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.baileyseymour\.com
RewriteRule ^(.*)$ http://www.baileyseymour.com/$1 [R=301,L]
</IfModule>
.htaccess is the right place to put them and that file should be in the same directory as your default home page.
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]