Im trying to achieve this
http://domain.com?q=page-slug to http://domain.com/page-slug
right now if I access this http://domain.com?q=page-slug my webpage is working, but I want clean URls like http://domain.com/page-slug
I used this code in my htaccess but returning 500 error
RewriteEngine On
RewriteRule ^(.*)$ ?q=$1 [L,QSA]
any help please.
Try this I am assuming you have index.php page which is handling the request.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)$ index.php?q=$1 [QSA,L]
If not index.php change to actual page you have.
Related
I would like to show certain content on my website. I choose the content based on a URL parameter, like page=about. This works well, and my URL looks like example.com/mysite/index.php?page=about. My issue is that I would like my URL to read example.com/mysite/about, where the last part is the name of the page parameter.
I am attempting to do this through htaccess. This is my exact code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
I see no change on my page nor to the URL structure. The URL still reads ...index.php?page=about. Am I doing something wrong? I tried this a bunch of different ways and I still get the same result. I also tried simply doing this, with no change:
RewriteEngine On
RewriteRule ^([a-z]+)\/([0-9]+)\/?$ index.php?page=$1 [NC]
I didn't think it was working, so I tried a redirect to some other site and it worked. Therefore, the htaccess file is getting read and able to function.
Any assistance would be helpful!
Thank you,
BP
You may use these 2 rules in your site root .htaccess:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+(mysite)/index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/mysite/([^/]+)/?$ [NC]
RewriteRule ^ index.php?page=%1 [L,QSA]
I made an URL Shortener and shortened links looks like this:
http://patison.eu/06uoM. My PHP code checks if this 06uoM is in my database - if yes it will redirect to the correct page, if not it will open index.php file from index_html directory. It's bad because when I write URL to image uploaded on server it will open index.php because URL is not in database...
http://patison.eu/forum/images/off.gif - see?
This is how .htaccess looks like:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?url=$1
Please help me solve this problem!
It sounds like you want to let 404 errors happen on URLs like
http://patison.eu/forum/images/off.gif
but not on URLs like
http://patison.eu/06uoM
If that is the case, you can change your .htaccess code to this to limit the type of URLs rewritten:
RewriteEngine on
# Limit rewrites to urls like '/06uoM' or '/06uoM/', but not like '/forum/images/off.gif'
RewriteCond %{REQUEST_URI} ^/[0-9a-z]{5}/?$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?url=$1
I am trying to rewrite the following URL via .htaccess:
http://website.com/dealer_home.php?id=dealer1
The result I am aiming for is this, where dealer1 is the username which is set as variable:
http://website.com/dealer1
I have tried this rule in .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)$ /dealer_home.php?id=$1 [L]
However I get "Internal Server Error" message when trying to load any of the website pages.
Can you provide some advice where I am doing wrong?
EDIT:
I tried also RewriteRule ^(.*)$ dealer_home.php?id=$1 [PT] but no success.
Thank you!
Maybe it's a conflict with existing files/folders and root uri.
Try this code instead
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /dealer_home.php?id=$1 [L]
This rule will match every url like domain.com/something if something is not an existing file or folder.
So if you have other rules then you should put them above this one.
EDIT: to avoid duplicate content and to redirect old format to new url format
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/dealer_home\.php\?id=([^&\s]+)\s [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /dealer_home.php?id=$1 [L]
I want to rewrite URL using .htaccess in codeigniter but it's not working. Can you please figure it out. Want to change URL from:
www.site.com/mauritius_holiday_rentals/apartment/anyname
to
www.site.com/mauritius_holiday_rentals/anyname
My current .htaccess file contains:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteRule ^mauritius_holiday_rentals/([A-Za-z0-9-]+)/?$ mauritius_holiday_rentals/apartment/$1 [L,QSA]
First four line is for removing index.php from URL which is working fine.
If routes file is set to access new url and you want to set redirection for old URLs then Use following code in .htaccess. otherwise let me know in detail what you want to do.
RewriteEngine on
RewriteBase /
RewriteRule /mauritius_holiday_rentals/apartment/$1 /mauritius_holiday_rentals/$1 [R=301,L]
Routes.php config file code
$route['mauritius_holiday_rentals/(:any)']="mauritius_holiday_rentals/apartment/$1";
Let me know if any problem.
RewriteEngine On
RewriteBase /yourProjectName/
RewriteCond $1 !^(images|stylesheets|javascript)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yourProjectName/index.php?/$1 [L]
Try to use codeigniter routing system
https://www.codeigniter.com/user_guide/general/routing.html
I am having some issues with url rewriting
I am using this as my code for rewrite in htaccess
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /pages.php?id=$1 [L]
this was my url
studentsassignmenthelp.com/pages.php?id=Marketing-Assignment-Help
after using the url rewrite i am getting this
studentsassignmenthelp.com/Marketing-Assignment-Help.html
but i need it without the html like the below one
studentsassignmenthelp.com/Marketing-Assignment-Help
if i use the below code to remove the .html than it shows error 500 server...
RewriteRule ^([^/]*)$ /pages.php?id=$1 [L]
I saw some example but after using them it shows 404 or 500 error
Try this,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !pages.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ pages.php?id=$1 [QSA,L]
try this:
RewriteEngine On
RewriteRule ^([^/]*)$ /pages.php?id=$1 [L]
redirectMatch 301 ^(.*).html $1
This is quite usefull to remove any url extension and avoid broken links.