Object not found error after rewrite the URL [duplicate] - .htaccess

This question already has an answer here:
htaccess RewriteRule results in "Object not found!"
(1 answer)
Closed 3 years ago.
I have two types of URL on my website which are
First URL set
Service name1
Second URL set
Service name1
Now what I am doing is, For the first URL, I want URL like
services/services_name1
So I used like below code in htaccess and it's working
RewriteRule ^services/services_name1$ services_name1
My issue is with the second URL.
For the second URL, I want my URL like
services/authors/services_name1
I tried below code in htaccess
RewriteRule ^/?services/authors/([0-9]+)$ /journel.php?name=$1
but it not working. I am getting 404.
I am using click here
.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTPS} off
RewriteRule ^home$ index
RewriteRule ^about-us$ aboutus
RewriteRule ^services/authors$ authors
RewriteRule ^/?services/authors/([0-9\w]+)$ /journel.php?name=$1
FileETag MTime Size
</IfModule>
Would you help me out with this issue?

the rule:
RewriteRule ^/?services/authors/([0-9]+)$ /journel.php?name=$1
only matches numbers(because of the 0-9) after /authors/ such as /authors/22/. To allow characters(words/dashes) \w can be used:
RewriteRule ^/?services/authors/([0-9\w]+)$ /journel.php?name=$1
Updated order with entire .htaccess:
# BEGIN WordPress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTPS} off
RewriteRule ^home$ index
RewriteRule ^about-us$ aboutus
RewriteRule ^services/authors$ authors
RewriteRule ^/?services/authors/([0-9\w]+)$ /journel.php?name=$1
FileETag MTime Size
</IfModule>
Checkout the regex cheatsheet: https://www.rexegg.com/regex-quickstart.html

Related

Redirect rule to change url parameters with slashes / in .htaccess file

I need to change url parameters with slashes.
My current working url is
https://www.example.com/Blog-Details.php?blog=test-title
I need to change it like below
https://www.example.com/Blog-Details.php/blog/test-title
My htaccess file is
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#RewriteRule ^([a-z_]+).html $1.php
RewriteRule ^([A-Za-z_-]+).html $1.php
RewriteRule ^([a-z]+)/([a-z]+)/(.*)\.html /market_material.php?ind=$3
#RewriteRule ^([A-Z]{2})/([\+a-z\ ]+)\.html$ /reports_content.php?
report_id=$1
#RewriteRule ^report/([0-9]+) /reports_content.php?report_id=$1
RewriteRule ^([0-9]+)/(.*)\.html /reports_content.php?report_id=$1
#RewriteRule ^blog/([0-9]+) /Blog-Details.php?blog=$1
#RewriteRule ^Blog-Details.html/([^/]+)?$ $1.php?blog=$2 [L]
RewriteRule ^([^.]+?)/?$ /Blog-Details.html?p=$1 [NC,L]
</IfModule>
I added this line to convert parameters with slashes
RewriteRule ^([^.]+?)/?$ /Blog-Details.html?p=$1 [NC,L]
Try using the following RewriteRule in your .htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} blog=(.+) [NC]
RewriteRule ^(.*)$ http://www.example.com/Blog-Details.php/%1? [R=301, NC, L]
This is grabbing your variable blog= using a condition and then adding it onto the end of your URL using %1. You'll notice I've also added a ? onto the end of the RewriteRule, this is to stop the original query string from appearing on the end of the URL.
The rewrite works by using 301 redirection, you might want to change this to 302 to make it a temporary redirect while testing.
Make sure you clear your cache before testing this.

URL rewrite for part of domain name

I feel this should be an easy fix but I'm struggling to get it done right.
I have the URL:
http://www.testing.com/toursgbr/my-post
http://www.testing.com/toursgbr/my-post-2
I need to rewrite the URL to:
http://www.testing.com/tours/gbr/my-post
http://www.testing.com/tours/gbr/my-post-2
I got as far as the following:
RewriteRule ^toursgbr/(.*) /tours\/gbr/$1 [L]
This is what's currently in the htaccess file:
RewriteEngine on
ErrorDocument 404 http://www.ausweb.com.au/web-hosting
AddHandler server-parsed html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^seabreezepark\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.seabreezepark\.com\.au$
RewriteRule ^/?$ "http\:\/\/theseabreezepark\.com\.au\/" [R=301,L]
RewriteRule ^toursgbr/(.+)$ /tours/gbr/$1 [NC,L]
and got nowhere pretty fast. I just want to look for the word "toursgbr" and change it to "tours/gbr" in summary.
Put the Following code at root .htaccess file :
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} !\s/+tours/gbr/ [NC]
# the above line will exclude any request having tours/gbr/ from the follwoing rule.
RewriteRule ^toursgbr/(.*)$ tours/gbr/$1 [R=302,L,NE]
# the above line will change any requested url having toursgbr/ to be tours/gbr/ temporary
# and you can change it to permanent by changing [R=302,L,NE] to [R=301,L,NE]
# but check the code as it is first then change it
RewriteRule ^tours/gbr/(.*)$ toursgbr/$1 [L,NC]
# the above line will internally map any request having tours/gbr/ to its original path
Try :
RewriteRule ^toursgbr/(.+)$ /tours/gbr/$1 [NC,L]
Do not use the full url in rewrite target if you want to internally redirect /toursgbr/foo to /tours/gbr/foo without changing the url in browser.
Your corrected htaccess :
ErrorDocument 404 http://www.ausweb.com.au/web-hosting
AddHandler server-parsed html
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?seabreezepark\.com\.au$
RewriteRule ^/?$ http://theseabreezepark.com.au/ [L,R=301]
RewriteRule ^toursgbr/(.+)$ /tours/gbr/$1 [NC,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Rewrite static html to dynamic php error bad flag delimiters

Having gone through some suggestions about rewriting static url to php url i have hit snag trying to redirect http://www.example.com/clothing to http://www.example.com/index.php?main_page=index&cPath=999
using this rule
RewriteRule ^clothing/index.html index.php?main_page=index&cPath=999 [L]
I keep getting
rewriterule: bad flag delimiter
even after changing/adding / and \ to the rule.
This is my .htaccess file
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# From Ultimate SEO URLs
RewriteRule ^(.*)-p-(.*).html$ index\.php?main_page=product_info&products_id=&% {QUERY_STRING} [L]
RewriteRule ^(.*)-c-(.*).html$ index\.php?main_page=index&cPath=&%{QUERY_STRING} [L]
RewriteRule ^(.*)-m-([0-9]+).html$ index\.php?main_page=index&manufacturers_id=&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pi-([0-9]+).html$ index\.php?main_page=popup_image&pID=&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pr-([0-9]+).html$ index\.php?main_page=product_reviews& products_id=&%{QUERY_STRING} [L]
RewriteRule ^(.*)-pri-([0-9]+).html$ index\.php?main_page=product_reviews_info&products_id=&%{QUERY_STRING} [L]
RewriteRule ^(.*)-ezp-([0-9]+).html$ index\.php?main_page=page&id=&%{QUERY_STRING} [L]
# All other pages
# Don't rewrite real files or directories
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*).html$ index\.php?main_page=&%{QUERY_STRING} [L]

replace word through htaccess

I have a wordpress site. Here is link to site. I want to redirect www.abc.com/?portfolios=letters to www.abc.com/?files=letters.
I tried editing in code, but din't worked.
Here is htaccess
Options +FollowSymLinks
RewriteEngine on
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^womackpi.com/?portfolio=(.+) womackpi.com/?files=$1 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
This should do:
RewriteRule ^abc.com/?portfolios=(.+) abc.com/?files=$1 [NC]
It works for me!
You will also need:
Options +FollowSymLinks
RewriteEngine on
Above the previous statement.
Query strings are not part of the URI that is used to match against the expression in RewriteRule..
Try replacing RewriteRule ^womackpi.com/?portfolio=(.+) womackpi.com/?files=$1 [NC] with:
RewriteCond %{HTTP_HOST} ^(www\.)?womackpi.com$ [NC]
RewriteCond %{QUERY_STRING} (^|&)portfolio=(.+)(&|$) [NC]
RewriteRule ^(.*)$ /$1?files=%2 [L]
Add an R inside the [L] brackets if you want to redirect the browser (changing the URL in the address bar).

.htaccess redirecting errors

First off I am using the Codeigniter Framework so this issue is a workaround the way CI process URLs along with the current redirects I have set up using mod_rewrite.
I am trying to get a URL like this /?gclid=somestringgoeshere to redirect to /index.php?/home/gclid/somestringgoeshere.
The current .htaccess I have set is below
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5_$6_$7 [L]
RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5_$6 [L]
RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5 [L]
RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4 [L]
RewriteRule ^([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3 [L]
RewriteRule ^([^_]+)-([^.]+)$ index.php?/$1_$2 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# This last condition enables access to the images and css folders, and the robots.txt file
# Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I am trying to use the following code right above the first set up rewrite conditions and rule's to catch it before it try's anything else
RewriteRule ^?gclid=(.*)$ index.php?/home/gclid/$1 [L]
and
RewriteRule ^\?gclid=(.*)$ index.php?/home/gclid/$1 [L]
and
RewriteRule ^/?gclid=(.*)$ index.php?/home/gclid/$1 [L]
All either don't show the correct page or come up with a 500 internal error.
The URI’s query can only be tested with the RewriteCond directive:
RewriteCond %{QUERY_STRING} ^gclid=(.*)
RewriteRule ^$ index.php?/home/gclid/%1 [L]
Or more general (will consider further query parameters):
RewriteCond %{QUERY_STRING} ^([^&]*&)*gclid=([^&]*)
RewriteRule ^$ index.php?/home/gclid/%2 [L]
Oh, by the way: RewriteCond directives only correspond to the first following RewriteRule directive.

Resources